import Tips from './Tips';

/**
 * 分享功能[todo]
 * 
 * @export
 * @class Share
 */
export default class Share {
    /**
     * 打开 分享
     * 
     * @static
     * 
     * @memberOf Share
     */
    static openShare(option = { title: '', url: '' }) {
        return new Promise((resolve, reject) => {
            plus.share.getServices(shares => {
                const items = shares.map(item => {
                    return {
                        title: item.description
                    };
                });
                Tips.action('分享', items)
                    .then(index => {
                        const share = shares[index - 1];
                        share.send({
                            content: option.title,
                            href: option.url,
                            extra: {
                                scene: "WXSceneTimeline"
                            }
                        }, () => {
                            resolve();
                        }, error => {
                            reject(error);
                        });
                    });
            }, error => {
                reject(error);
            });
        });
    }
}